package com.wh.wisdomsite.xbox.pr.service.impl;

import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.wh.wisdomsite.xbox.pr.dao.ProjectMapper;
import com.wh.wisdomsite.xbox.pr.entity.Project;
import com.wh.wisdomsite.xbox.pr.service.IProjectService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 工程项目projectService业务层实现类
 *
 * @author 蔡道行
 * @version V1.0
 * @package com.wh.wisdomsite.xbox.pr.service.impl
 * @date 17:19 2018/8/2
 * @Copyright 公司版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2014
 */
@Service("projectService")
@Transactional(rollbackFor = {Exception.class, RuntimeException.class})
public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, Project> implements IProjectService {

    private static final Log logger = LogFactory.getLog(ProjectServiceImpl.class);

    @Autowired
    private ProjectMapper projectMapper;

    @Override
    public Map<String, Object> getMapById(Serializable id) {
        return projectMapper.getMapById(id);
    }

    @Override
    public Page<Map<String, Object>> getMapsPage(Page page, Wrapper<Project> wrapper) {
        SqlHelper.fillWrapper(page,wrapper);
        page.setRecords(this.baseMapper.getMapsPage(page,wrapper));
        return page;
    }


    @Override
    public List<Project> selectProjectListByCompanyId(Integer companyId) {
        return projectMapper.selectProjectListByCompanyId(companyId);
    }

    @Override
    public List<Project> selectProjectListByOfficeId(Integer officeId) {
        return projectMapper.selectProjectListByOfficeId(officeId);
    }

    @Override
    public List<String> selectByCompCode(String compCode, String officeCode) {
        List<Project> projectList = projectMapper.selectByCode(compCode,officeCode);
        List<String> projectIds = new ArrayList<String>();
        if(projectList.size() > 0){
            for(Project project : projectList){
                projectIds.add(project.getPrId());
            }
        }
        return projectIds;
    }

    @Override
    public Page<Map<String, Object>> selectPageByCode(Page page, Wrapper<Project> wrapper,String compCode, String officeCode) {
        SqlHelper.fillWrapper(page, wrapper);
        page.setRecords(this.baseMapper.selectMapByCode(page, wrapper,compCode,officeCode));
        return page;
    }

    @Override
    public Map<String, Object> getCcProjectMapById(Serializable id) {
        return projectMapper.getCcProjectMapById(id);
    }

    @Override
    public Page<Map<String, Object>> getCcProjectMapsPage(Page page, Wrapper<Project> wrapper) {
        SqlHelper.fillWrapper(page,wrapper);
        page.setRecords(this.baseMapper.getCcProjectMapsPage(page,wrapper));
        return page;
    }

    @Override
    public Project getById(String prId) {
        return projectMapper.getById(prId);
    }
}
